package com.zry.traced.ui.base

import android.app.Dialog
import android.content.pm.ActivityInfo
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.view.Window
import com.zry.traced.animation.RecyclerViewUtilKt
import com.zry.traced.config.MyActivityManager
import com.zry.traced.config.MyApplication
import com.zry.traced.greendao.gen.FlowRecordInfoDao
import com.zry.traced.greendao.gen.OutTreasuryCodeDao
import com.zry.traced.greendao.gen.PackingOperationInfoDao
import com.zry.traced.greendao.gen.PutStorageCodeDao
import com.zry.traced.retrofit.ApiSupport
import com.zry.traced.utils.ToastUtil


abstract class BaseActivity : PermissionActivity(), ApiSupport {
    var myApplication: MyApplication? = null
    var recyclerViewUtilKt: RecyclerViewUtilKt? = null
    var myActivityManager: MyActivityManager? = null
    var loadingDialog: Dialog? = null
    var viewDataBinding: ViewDataBinding? = null

    var outTreasuryCodeDao: OutTreasuryCodeDao? = null
    var flowRecordInfoDao: FlowRecordInfoDao? = null
    var putStorageCodeDao: PutStorageCodeDao? = null
    var packingOperationInfoDao: PackingOperationInfoDao? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
        viewDataBinding = getDataBinding()





        myActivityManager = MyActivityManager.getActivityManager()
        myActivityManager?.addActivity(this)
        myActivityManager?.addPermissionActivity(this)
        myApplication = MyApplication.instance()
        //禁止横竖屏切换
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

        loadingDialog = ToastUtil.loadingDialog(this)


        outTreasuryCodeDao = myApplication?.getDaoSession()!!.outTreasuryCodeDao
        flowRecordInfoDao = myApplication?.getDaoSession()!!.flowRecordInfoDao
        putStorageCodeDao = myApplication?.getDaoSession()!!.putStorageCodeDao
        packingOperationInfoDao = myApplication?.getDaoSession()!!.packingOperationInfoDao


        initData()
    }


    private fun getDataBinding(): ViewDataBinding {
        return DataBindingUtil.setContentView(this, getLayoutId())
    }

    protected abstract fun getLayoutId(): Int
    protected abstract fun initData()



    protected fun toast(toastMessage: String) {
        ToastUtil.toast(this, toastMessage)
    }


    override fun onDestroy() {
        super.onDestroy()
        myActivityManager?.removePermissionActivity(this)
        myActivityManager?.finishActivity()
    }
}
